<?php

class M_agenda extends CI_Model{
	
	//var $template = 'admin/admin_template';
	
	function __construct(){
		parent::__construct();
	}
	
	function create($tema,$isi_agenda,$tempat,$tgl_mulai,$tgl_selesai,$tgl_post, $gambar,$seo){
		$data = array(
		'tema' =>$tema,
		'isi_agenda'=> $isi_agenda,
		'tempat' => $tempat,
		'tgl_mulai' => $tgl_mulai,
		'tgl_selesai' => $tgl_selesai,
		'tgl_posting' => $tgl_post,
		'gambar' => $gambar,
		'seo' => $seo
		);
		
		$this->db->insert('agenda', $data);
		if ($this->db->affected_rows() == 1) {
			return TRUE;
		}
		return FALSE;
	}
	
	function getTable($perPage = 0, $offset = 0) {
        $this->db->select('*');
		$this->db->order_by('id_agenda', 'DESC');
        $this->db->limit($perPage, $offset);
        $query = $this->db->get('agenda');

        return $query->result_array();
        
    }
	
	function getAllData(){
		$this->db->select('*');
		$this->db->order_by('id_agenda', 'DESC');
        $query = $this->db->get('agenda');
		
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
	}
	
	function getDataById($id){
		$this->db->select('*');
		$this->db->where('id_agenda', $id);
		$query = $this->db->get('agenda');
		
		if($query->num_rows() == 1){
			return $query->result_array();
		}
	}
	
	function update($id,$tema,$isi_agenda,$tempat,$tgl_mulai,$tgl_selesai,$gambar,$seo){
		$data = array(
		'tema' =>$tema,
		'isi_agenda'=> $isi_agenda,
		'tempat' => $tempat,
		'tgl_mulai' => $tgl_mulai,
		'tgl_selesai' => $tgl_selesai,
		'gambar' => $gambar,
		'seo' => $seo
		);
		$this->db->where('id_agenda', $id);
		$this->db->update('agenda', $data);
		
		if ($this->db->affected_rows() == 1) {

            return TRUE;
        }
        return FALSE;
	}
	
	function delete($id){
		$this->db->where('id_agenda', $id);
		$this->db->delete('agenda');
		if ($this->db->affected_rows() == 1) {

            return TRUE;
        }
        return FALSE;
	}
	
	function search($key){
		$this->db->select('*');
		$this->db->like('tema', $key);
		$this->db->order_by('id_agenda', 'DESC');
		$query = $this->db->get ('agenda');
		return $query->result_array();
	}

}